package com.qisu.dao;

import java.util.HashMap;
import java.util.Map;

import org.beetl.sql.core.SQLManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.qisu.model.vo.PayMent;
import com.qisu.model.packet.SettlementPacket;
import com.qisu.model.vo.ChargeQuantityAndPolicy;
import com.qisu.model.vo.Gun;

/**
 * 
 * @author li
 *
 */
//@Repository
@Component
public class OrderDao {
	@Autowired
	private SQLManager sqlManager;
	
	public void updateOrderInfo(Map<String, Object> params) {
		sqlManager.update("order.updateOrderInfo", params);
	}

	public Gun getOrderPileAndGun(String orderId) {
		Map<String, String> hamap = new HashMap<>(1);
 		hamap.put("orderId", orderId);
		return sqlManager.selectUnique("order.getGunInfo", hamap, Gun.class);
	}

	
	public PayMent getOrderInfo(String orderId) {
		Map<String, String> hamap = new HashMap<>(1);
 		hamap.put("orderId", orderId);
		try {
			return sqlManager.selectUnique("order.getPayMentInfo", hamap, PayMent.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	
	public ChargeQuantityAndPolicy getChargeQuantityAndPolicy(String orderId) {
		Map<String, String> hamap = new HashMap<>(1);
		hamap.put("orderId", orderId);
		return sqlManager.selectUnique("order.getChargeQuantityAndPolicy", hamap, ChargeQuantityAndPolicy.class);
	}

	
	public ChargeQuantityAndPolicy getChargeQuantityAndPolicyByGun(String pileSerial, int gunNo) {
		Map hamap = new HashMap<>(2);
		hamap.put("pileSerial", pileSerial);
		hamap.put("gunNo", gunNo);
		return sqlManager.selectUnique("order.getChargeQuantityAndPolicyByGun", hamap, ChargeQuantityAndPolicy.class);
	}

	
	public void updateOrder02to03(SettlementPacket packet) throws Exception{
		System.out.println(packet);
		int update = sqlManager.update("order.updateOrder02to03", packet);
		System.out.println(update);
		
	}

	
	public void updateRefund(Map map) {
		sqlManager.update("order.updateRefund", map);
		
	}

	
	public void updateOrder03to04(Map map){
		sqlManager.update("order.updateOrder03to04", map);
		
	}

	public void startCharge(Map map) {
		sqlManager.update("order.startCharge", map);
	}

	public void updateRefundto2(Map map) {
		sqlManager.update("order.updateRefundto2", map);
		
	}

	



}
